package com.xm.xmapp;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.xm.xmapp.adapter.FragmentStatePagerAdapter;
import com.xm.xmapp.adapter.MyPagerAdapters;
import com.xm.xmapp.app.Type;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.fragment.CarPayFragment;
import com.xm.xmapp.fragment.WalletPayFragment;
import com.xm.xmapp.tools.AndroidTool;
import com.xm.xmapp.tools.Tools;

public class PayActivity extends BaseActivity  {
	private ViewPager vp;
	private MyPagerAdapters adapter;
	private WalletPayFragment carFeedBackFragment;
	private CarPayFragment pileFeedBackFragment;
	private TabLayout tab;
	private int flag = 0;
	String[] title = { "钱包充值", "车辆押金" };

	@Override
	public Object dataChang(int flag, Object data) {
		switch (flag) {
		case Type.A_Pay.DEFAULT:
			finish();
			break;
		default:
			break;
		}
		return super.dataChang(flag, data);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_feedback);
	}

	@Override
	public void initView() {
		vp = (ViewPager) findViewById(R.id.vp);
		tab = (TabLayout) findViewById(R.id.tab);
	}

	@Override
	public void initData() {

		flag = getIntent().getIntExtra("flag", 0);
		String initMoney = getIntent().getStringExtra("initMoney");
		setMyTitle("钱包充值");
		boolean isAuthorize = getIntent().getBooleanExtra("isAuthorize", false);
		ArrayList<Fragment> fragmentList = new ArrayList<Fragment>();
		carFeedBackFragment = new WalletPayFragment(isAuthorize);
		pileFeedBackFragment = new CarPayFragment(isAuthorize, initMoney);
		fragmentList.add(carFeedBackFragment);
		fragmentList.add(pileFeedBackFragment);
		adapter = new MyPagerAdapters(title ,getSupportFragmentManager(),
				fragmentList);
		vp.setAdapter(adapter);
		vp.setCurrentItem(flag);
		vp.setOffscreenPageLimit(2);
		setPage();
		tab.setupWithViewPager(vp);
		tab.post(new Runnable() {
			@Override
			public void run() {
				int marig = Tools.dp2px(10);
				AndroidTool.setIndicator(tab,marig,marig);
			}
		});
	}

	private void setPage() {
		setMyTitle(title[flag]);

	}

	@Override
	public void initEvent() {
		vp.addOnPageChangeListener(new OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				flag = position;
				setPage();

			}

			@Override
			public void onPageScrolled(int position, float positionOffset,
					int positionOffsetPixels) {

			}

			@Override
			public void onPageScrollStateChanged(int state) {

			}
		});
	}


}
